<?php require_once 'cabecalho.php'; ?>
<?php $noticia    = DB::fetchTodos("*","noticias",null,1); ?>
<?php $categorias = DB::fetchTodos("*","categorias"); ?>
<?php $arquivo    = DB::parseSql("SELECT id, mes as mes_int, monthname(data) as mes, YEAR(data) AS ano FROM noticias GROUP BY mes"); ?>
<?php $charlim    = 400; ?>

<script>
function texto(obj){
	document.getElementById("k-texto").style.display="block";
	document.obj.style.display="none";
}

function abrirTexto(id){
	jQuery.post("noticia.php",{id:id},function(html){
		jQuery(".article").html(html);
	});
}

function noticia(categoria,mes){
	jQuery.post("lista-noticias.php?categoria="+categoria+"&mes="+mes,{},function(html){
		jQuery("#texto-noticia").html(html);
	});
}
</script>
				
<div class="separator top-separator content left"></div>
<div class="separator top-separator content right"></div>

<div id="main" class="content">	
	
	<div class="blog">
	
		<article class="article">

			<details class="article-info details metadata">
				<span class="date"><?php echo $noticia[0]["data"]; ?></span>
				<span class="article-author">Escrito por Bagdad Café</span>
			</details>

			<h2 class="article-title styled-header">
				<a href="#"><?php echo $noticia[0]["titulo"]; ?></a>
			</h2>

			<div class="article-body">
				<p><a class="thumbnail" href="admin/<?php echo $noticia[0]["arquivo"]; ?>" rel="lightbox[]" title="Image">
				<img src="admin/<?php echo $noticia[0]["arquivo"]; ?>" alt="Image" width="420" height="177" /></a>
				<?php echo substr($noticia[0]["texto"],0,$charlim); ?></p>
				<p id='k-texto' style="display: none;">
					<?php echo substr($noticia[0]["texto"],$charlim,strlen($noticia[0]["texto"])); ?>
				</p>
			</div>

			<a class="readmore" href="javascript:texto(this);" onclick="">
			<span class="leaf"></span>Continue Lendo: <?php echo $noticia[0]["titulo"]; ?></a>
		</article>

		<div class="clear"></div>
		
									
	</div>
 
</div><!-- end main -->

<div class="sidebar content">

	<div class="module  menu cols-2 col-first">
		<div>
			<h3>Arquivo</h3>
			<ul class="archive-module menu cols-2 col-last">
				<?php foreach($arquivo as $v): ?>
				<li>
					<a href="javascript:noticia('',<?php echo $v["mes_int"]; ?>);"><?php echo $v["mes"]; ?>, <?php echo $v["ano"]; ?></a>
				</li>
				<?php endforeach; ?>
			</ul>
		</div>
	</div>
	
	<div class="module  menu cols-2 col-last">
		<div>
			<h3>Categorias</h3>
			<ul class="archive-module menu cols-2 col-last">
				<?php foreach($categorias as $v): ?>
				<li>
					<a href="javascript:noticia(<?php echo $v["id"]; ?>,'');"><?php echo $v["categoria"]?></a>
				</li>
				<?php endforeach; ?>
			</ul>
		</div>
	</div>
	
	<div class="separator clear"></div>
	
	<div id='texto-noticia'>

	</div>
					
</div><!-- end sidebar -->
									
						
<?php require_once 'rodape.php'; ?>